//
//  YTBaseTableViewController.swift
//  Rhythm_SinaWeibo
//
//  Created by Mr.Rhythm on 9/21/15.
//  Copyright © 2015 Mr.Rhythm. All rights reserved.
//

import UIKit

/// 表格控制器的基类，根据用户登录状态，显示不同页面
class YTBaseTableViewController: UITableViewController {
    
    // 标记用户登录状态
    var userLoginStatus = false
    // 访客视图
    var visitorView : YTVisitorView?
    
    // 调整视图结构
    override func loadView() {
        userLoginStatus ? super.loadView() : setupVisitorView()
    }
    
    override func viewDidAppear(animated: Bool) {
        super.viewDidAppear(animated)
    }
    
    // 访客界面
    private func setupVisitorView() {
        visitorView = YTVisitorView()

        view = visitorView

//        // 添加监听方法
        visitorView?.YTLoginButton.addTarget(self, action: "visitorViewDidLogin", forControlEvents: UIControlEvents.TouchUpInside)
        visitorView?.YTRegisterButton.addTarget(self, action: "visitorViewDidRegister", forControlEvents: UIControlEvents.TouchUpInside)
        
    }
    
    @objc private func visitorViewDidLogin() {
        let vc = YTOAuthViewController()
        let nav = UINavigationController(rootViewController: vc)
        
        presentViewController(nav, animated: true, completion: nil)
    }
    
    @objc private func visitorViewDidRegister() {
        print("点击了注册按钮", terminator: "")
    }
}
